package com.wencai.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author wangpan
 * @date 2023/4/17
 */
public class ConvertedStock implements Comparable<ConvertedStock> {
    private String name;
    private int times;
    private double maxIncrement;
    private List<DateIncrement> list = new ArrayList<>();

    public ConvertedStock(String name, int times) {
        this.name = name;
        this.times = times;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTimes() {
        return times;
    }

    public void setTimes(int times) {
        this.times = times;
    }

    public List<DateIncrement> getList() {
        return list;
    }

    public void add(DateIncrement dateIncrement) {
        list.add(dateIncrement);
    }

    public double getMaxIncrement() {
        return maxIncrement;
    }

    public void setMaxIncrement() {
        this.maxIncrement = list.stream().map(item -> item.getIncrement()).max(Double::compareTo).get();
    }

    public void sort() {
        Collections.sort(list);
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("ConvertedStock{");
        sb.append("name='").append(name).append('\'');
        sb.append(", times=").append(times);
        sb.append(", maxIncrement=").append(maxIncrement);
        sb.append(", list=").append(list);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public int compareTo(ConvertedStock o) {
        int i = Integer.valueOf(o.times).compareTo(times);
        return i == 0 ? o.name.compareTo(name) : i;
    }
}
